import React, {useRef} from 'react';

function Child(props) {
    const userNameRef = useRef()

    function getInfo(){
        console.log(userNameRef.current.innerText)
    }
    return (
        <div>
            Child
            <button onClick={getInfo}>点击获取内容</button>
            <p ref={userNameRef}>123</p>
        </div>
    );
}

export default Child;